package com.xuruzi.demo.util.api;

import com.alibaba.fastjson.JSON;
import com.xuruzi.demo.util.BaseResponse;
import com.xuruzi.demo.util.WxUtils;
import com.xuruzi.demo.util.response.GetUserInfoResponse;

/**
 * Created by xuruzi on 2020/3/27.
 */
public class UserApi extends BaseApi {
    public GetUserInfoResponse getUserInfo(String code,String access_token){
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("http://")
                .append(WxUtils.getDomain()).append("/cgi-bin/user/getuserinfo?")
                .append("code=").append(code).append("&")
                .append("access_token=").append(access_token);
        BaseResponse baseResponse = this.excuteGet(stringBuilder.toString());
        String result = this.isSuccess(baseResponse.getErrcode()) ? baseResponse.getErrmsg() : JSON.toJSONString(baseResponse);
        GetUserInfoResponse response = JSON.parseObject(result,GetUserInfoResponse.class);
        return response;
    }
}
